/*  1:   */ package org.jetbrains.io;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.Disposable;
import com.intellij.util.net.NetUtils;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import org.jetbrains.ide.BuiltInServerManager;
import org.jetbrains.ide.CustomPortServerManager;
import org.jetbrains.ide.CustomPortServerManager.CustomPortService;

import java.net.InetSocketAddress;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */ 
/* 13:   */ final class SubServer
/* 14:   */   implements CustomPortServerManager.CustomPortService, Disposable
/* 15:   */ {
/* 16:28 */   private final ChannelRegistrar a = new ChannelRegistrar();
/* 17:   */   private final CustomPortServerManager b;
/* 18:   */   private final ServerBootstrap c;
/* 19:   */   
/* 20:   */   public SubServer(CustomPortServerManager paramCustomPortServerManager, EventLoopGroup paramEventLoopGroup)
/* 21:   */   {
/* 22:34 */     this.b = paramCustomPortServerManager;
/* 23:35 */     paramCustomPortServerManager.setManager(this);
/* 24:36 */     this.c = BuiltInServer.createServerBootstrap(paramEventLoopGroup, this.a, paramCustomPortServerManager.createXmlRpcHandlers());
/* 25:   */   }
/* 26:   */   
/* 27:   */   public boolean bind(int paramInt)
/* 28:   */   {
/* 29:40 */     if ((!this.b.isAvailableExternally()) && (paramInt == BuiltInServerManager.getInstance().getPort())) {
/* 30:41 */       return true;
/* 31:   */     }
/* 32:   */     try
/* 33:   */     {
/* 34:45 */       this.c.localAddress(this.b.isAvailableExternally() ? new InetSocketAddress(paramInt) : new InetSocketAddress(NetUtils.getLoopbackAddress(), paramInt));
/* 35:46 */       this.a.add(this.c.bind().syncUninterruptibly().channel());
/* 36:47 */       return true;
/* 37:   */     }
/* 38:   */     catch (Exception localException)
/* 39:   */     {
/* 40:   */       try
/* 41:   */       {
/* 42:51 */         NettyUtil.log(localException, BuiltInServer.LOG);
/* 43:   */       }
/* 44:   */       finally
/* 45:   */       {
/* 46:54 */         this.b.cannotBind(localException, paramInt);
/* 47:   */       }
/* 48:   */     }
/* 49:56 */     return false;
/* 50:   */   }
/* 51:   */   
/* 52:   */   public boolean isBound()
/* 53:   */   {
/* 54:62 */     return !this.a.isEmpty();
/* 55:   */   }
/* 56:   */   
/* 57:   */   private void a()
/* 58:   */   {
/* 59:66 */     this.a.close(false);
/* 60:   */   }
/* 61:   */   
/* 62:   */   public boolean rebind()
/* 63:   */   {
/* 64:71 */     a();
/* 65:72 */     return bind(this.b.getPort());
/* 66:   */   }
/* 67:   */   
/* 68:   */   public void dispose()
/* 69:   */   {
/* 70:77 */     a();
/* 71:78 */     this.b.setManager(null);
/* 72:   */   }
/* 73:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.io.SubServer

 * JD-Core Version:    0.7.0.1

 */